package com.uphone.magicleafteacher.pro.activity;

import android.view.View;

import com.radish.baselibrary.Intent.IntentData;
import com.uphone.magicleafteacher.MyApp;
import com.uphone.magicleafteacher.base.BaseListActivity;
import com.uphone.magicleafteacher.http.ApiService;
import com.uphone.magicleafteacher.pro.adapter.BookBorrowingDetailAdapter;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.util.GsonUtils;
import com.uphone.magicleafteacher.vo.BookBorrowingBean;
import com.uphone.magicleafteacher.vo.BookBorrowingDetailBean;
import com.uphone.magicleafteacher.vo.BookBorrowingDetailEvent;
import com.uphone.magicleafteacher.vo.WorkcorrectionEvent;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

public class BookBorrowingDetailActivity extends BaseListActivity<BookBorrowingBean.FollowWorkBean.FinishedStudentsBean, BookBorrowingDetailAdapter> {
    @IntentData
    private int id;
    @IntentData
    private String title;

    @Override
    protected void initLayoutBefore() {
        super.initLayoutBefore();
        isEventBus = true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onRefresh(BookBorrowingDetailEvent event) {
        //刷新
        initData();
    }

    @Override
    protected Observable<ResponseBody> loadData(ApiService apiService) {
        return MyApp.apiService(ApiService.class)
                .finishedStudents(id + "");
    }

    @Override
    protected List<BookBorrowingBean.FollowWorkBean.FinishedStudentsBean> getDataList(String json) {
        BookBorrowingDetailBean bookBorrowingBean = GsonUtils.getGson().fromJson(json, BookBorrowingDetailBean.class);
        if (bookBorrowingBean != null)
            return bookBorrowingBean.getFinishedStudent();
        return null;
    }

    @Override
    protected void itemClick(BookBorrowingDetailAdapter adapter, View view, int position) {
        CommonUtil.startIntentTitle(this, VoiceReadActivity.class, mAdapter.getItem(position).getFollowWorkId(), mAdapter.getItem(position).getStudentName());
    }

    @Override
    protected BookBorrowingDetailAdapter initAdapter() {
        return new BookBorrowingDetailAdapter();
    }

    @Override
    protected void initBundle() {

    }

    @Override
    protected void initTitle() {
        initTitle(CommonUtil.getStr(title));
        setEnableLoadMore(false);
    }
}
